import http from "./base";
import {ApiFindGoodsDetailProps, ApiFindGoodsProps} from "./type";

const goods = {
    detail: "/tb/detailInfo",
};

//包装后的商品详情
export const apiGetGoodsDetail = (data: ApiFindGoodsDetailProps) => http({url: goods.detail, data: data});
//物料搜索
export const apiFindGoods = async (data: ApiFindGoodsProps) => {
    const res: any = await http({
        url: "/tb/material/optional",
        data: data,
    });
    return {
        data: res.data?.tbk_dg_material_optional_response?.result_list?.map_data || [],
        total: res.data?.tbk_dg_material_optional_response?.total_results || 10,
    };
};
//物料精选
export const apiGoodGoods = async (materialId, query?: any) => {
    const params = query ? query : {};
    const res: any = await http({
        url: "/tb/optimus/material",
        data: {materialId, ...params},
    });
    return res.data?.tbk_dg_optimus_material_response?.result_list?.map_data || [];
};
//权益 无数据
export const apiRights = () => {
    return http({
        url: "/tb/optimus/material",
        data: {promotionId: 62191},
    });
};

//官方活动转链接
export const apiActiveUrl = () => {
    return http({
        url: "/tb/activity/info/get",
    });
};

//阿里妈妈优惠券
export const apiCoupon = async (data) => {
    const res: any = await http({
        url: "/tb/tbk/coupon/get",
        data,
    });
    return res.data.tbk_coupon_get_response.data;
};

//淘口令
export const apiKLCreate = (url) => {
    return http({
        url: "/tb/tpwd/create",
        data: {url},
    });
};

//店铺查找
export const apiFindShop = async (name) => {
    const res: any = await http({
        url: "/tb/shop/get",
        data: {q: name, fields: "user_id,shop_title,shop_type,seller_nick,pict_url,shop_url"},
    });
    return res.data.tbk_shop_get_response.results.n_tbk_shop || [];
};

//长连接转短链接
export const apiChangeUrl = async (url: string) => {
    const res: any = await http({
        url: "/tb/spread/get",
        data: {url: "https:" + url},
    });
    return res.data?.tbk_spread_get_response?.results.tbk_spread[0]?.content || "";
};

//查询配置项
export const apiFindInfo = (type: number) => {
    return http({url: "/sys/config/img/list", data: {type}});
};

//一级分类查找二级分类
export const apiSecondLevelFindInfo = (pkId: number) => {
    return http({url: "/sys/config/img/itemList", data: {pkId}});
};

//美团活动查询
export const apiActionFind = () => {
    return http({url: "/prmo/list", data: {queryType: 1}});
};
